from django.http import HttpResponseRedirect
from django.utils.deprecation import MiddlewareMixin


class AddHeaderMiddlewareMixin(MiddlewareMixin):

    def process_response(self, request, response):
        # 检查响应是否是重定向响应
        if isinstance(response, HttpResponseRedirect):
            # 添加自定义的请求头
            response['Access-Control-Allow-Origin'] = '*'

        return response